package com.shd.edanpei.ui.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.ImageDecoder;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.OrderDetailsModel;
import com.shd.edanpei.customer.activity.ListActivity;
import com.shd.edanpei.enums.OrderTypeEnum;
import com.shd.edanpei.ui.activity.FileListActivity;
import com.shd.edanpei.ui.activity.FileListPersonalAndEnterpActivity;
import com.shd.edanpei.util.GsonUtil;

/**
 * Created by mc on 2018/9/20.
 * 我的订单 状态
 */

public class MeCustomerView extends LinearLayout {

    private OrderDetailsModel model;

    TextView tvName,tvMyName,tvMyCard,tvMyMoney,tvMyInterest,tvIsUpload;

    public MeCustomerView(Context context, OrderDetailsModel model) {
        super(context);
        this.model = model;
        initView();
    }


    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.meorder_customer_view, this);
        tvName = findViewById(R.id.tv_name);
        tvMyName = findViewById(R.id.tv_my_name);
        tvMyCard = findViewById(R.id.tv_my_card);
        tvMyInterest = findViewById(R.id.tv_my_interest);
        tvMyMoney = findViewById(R.id.tv_my_money);
        tvIsUpload = findViewById(R.id.tv_is_upload);

        tvName.setText(model.getCustomerInfo().getCustomerName() + "订单信息");
        tvMyName.setText(model.getCustomerInfo().getCustomerName());
        String idcard=model.getCustomerInfo().getIdCardNo().isEmpty()?"":"************"+model.getCustomerInfo().getIdCardNo().substring(model.getCustomerInfo().getIdCardNo().length()-4,model.getCustomerInfo().getIdCardNo().length());
        tvMyCard.setText(idcard);
        tvMyMoney.setText(model.getBaseInfo().getApplyAmount());
       // tvMyCard.setText(model.getBaseInfo().getApplyInterest());
        tvIsUpload.setVisibility(null!=model.getImgInfo().getIdCardPic()&&model.getImgInfo().getIdCardPic().size()>0?VISIBLE:GONE);
        if(null!=model.getImgInfo().getBusinessCert()||null!=model.getImgInfo().getOtherHouseCert()
                ||null!=model.getImgInfo().getCarCert()||null!=model.getImgInfo().getIdCardPic()
                ||null!=model.getImgInfo().getCarWarranty()
                ||null!=model.getImgInfo().getMaritalCert()
                ||null!=model.getImgInfo().getRoomCert()){
            tvIsUpload.setVisibility(VISIBLE);
        }else{
            tvIsUpload.setVisibility(GONE);
        }

        findViewById(R.id.ll_customer_info).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString(Constant.TITLE, "客户个人信息");
                bundle.putString(Constant.DATA, GsonUtil.toJson(model.getCustomerInfo().getDataList()));
                Intent intent = new Intent(getContext(), ListActivity.class);
                intent.putExtras(bundle);
                getContext().startActivity(intent);
            }
        });
        findViewById(R.id.ll_customer_data).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString(Constant.TITLE, "订单所需材料");
                bundle.putString(Constant.DATA, GsonUtil.toJson(model.getApplyInfo().getDataListPersional(model.getBaseInfo(),model)));
                Intent intent = new Intent(getContext(), ListActivity.class);
                intent.putExtras(bundle);
                getContext().startActivity(intent);
            }
        });
        findViewById(R.id.ll_customer_pic).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt(Constant.TYPE, Constant.SHOW);
                bundle.putInt(Constant.ORDER_TYPE, model.getBaseInfo().getOrderType());
                bundle.putParcelable(Constant.DATA, model.getImgInfo());
                Intent intent = new Intent(getContext(), FileListActivity.class);
                intent.putExtras(bundle);
                getContext().startActivity(intent);
            }
        });
    }

}
